package com.youxin.infra.io;

import com.alibaba.fastjson.JSONObject;
import com.youxin.infra.entity.Item;
import org.apache.commons.lang3.StringUtils;
import org.apache.flink.api.common.serialization.DeserializationSchema;
import org.apache.flink.api.common.typeinfo.TypeInformation;

import java.io.IOException;
import static java.nio.charset.StandardCharsets.UTF_8;

/**
 * @program: userPortrait
 * @description:
 * @author: sunteng
 * @create: 2020-08-18 11:08
 **/
public class KafkaDeserialFlaMess implements DeserializationSchema<Item> {
    @Override
    public Item deserialize(byte[] message) throws IOException {
        String value = new String(message, UTF_8);
        if (StringUtils.isNotEmpty(value)) {
            return JSONObject.parseObject(value, Item.class);
        }
        return null;
    }

    @Override
    public TypeInformation<Item> getProducedType() {
        return TypeInformation.of(Item.class);
    }

    @Override
    public boolean isEndOfStream(Item nextElement) {
        return false;
    }
}
